home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
haeberli
/
fonttools
/
drawfont.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
4KB
|
210 lines
/*
* Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
/*
* drawfont -
* Draw an object font.
*
* Paul Haeberli - 1990
*
*/
#include "gl.h"
#include "device.h"
#include "stdio.h"
#include "objfnt.h"
#include "path.h"
#include "vect.h"
#define ZSCALE (25.0)
float fgetmousex();
float fgetmousey();
printdoc()
{
fprintf(stderr,"\n");
fprintf(stderr,"drawfont instructions\n");
fprintf(stderr,"\n");
fprintf(stderr," 1. Use the LEFTMOUSE and slide left to right to see a character big\n");
fprintf(stderr," 2. Press the MIDDLEMOUSE and drag around to see a maginified verison of character\n");
fprintf(stderr,"\n");
}
main(argc,argv)
int argc;
char **argv;
{
objfnt *fnt;
short val;
float pos;
int i, opos, newpos;
int cmin, nchar;
char title[256];
float xpos, ypos;
if( argc<2 ) {
fprintf(stderr,"usage: drawfont file.of\n");
exit(1);
}
fontname(argv[1]);
fnt = readobjfnt(argv[1]);
keepaspect(5,4);
sprintf(title,"drawfont %s",argv[1]);
winopen(title);
subpixel(1);
RGBmode();
doublebuffer();
gconfig();
cpack(0x00ffffff);
clear();
swapbuffers();
makearray(fnt);
printdoc();
qdevice(ESCKEY);
qdevice(LEFTMOUSE);
qdevice(MIDDLEMOUSE);
qdevice(RIGHTMOUSE);
opos = -1;
cmin = fnt->charmin;
nchar = fnt->nchars;
while(1) {
switch(qread(&val)) {
case ESCKEY:
exit(0);
case REDRAW:
makearray(fnt);
break;
case LEFTMOUSE:
if(val) {
while(getbutton(LEFTMOUSE)) {
pos = fgetmousex();
newpos = cmin+(int)(nchar*pos);
if(newpos != opos) {
showchar(fnt,newpos,0);
opos = newpos;
}
}
}
break;
case MIDDLEMOUSE:
if(val) {
while(getbutton(MIDDLEMOUSE)) {
xpos = fgetmousex();
ypos = fgetmousey();
ortho2(-1.5/ZSCALE,13.5/ZSCALE,-2.0/ZSCALE,10.0/ZSCALE);
translate(-15.0*xpos,-12.0*ypos,0.0);
showchar(fnt,newpos,2);
}
ortho2(-1.5,13.5,-2.0,10.0);
showchar(fnt,newpos,0);
}
break;
}
}
}
makearray(fnt)
objfnt *fnt;
{
reshapeviewport();
ortho2(-1.5,13.5,-2.0,10.0);
cpack(0x00ffffff);
clear();
drawobjfnt(fnt);
swapbuffers();
}
showchar(fnt,c,psize)
objfnt *fnt;
int c, psize;
{
int didit;
char str[2], doc[256];
cpack(0x00ffffff);
clear();
cpack(0x000000ff);
rectf(2.0,2.0,2.05,2.05);
cpack(0x00000000);
fontmoveto(2.0,2.0);
fontsetsize(8.0);
str[0] = c;
str[1] = 0;
fontmoveto(2.0,2.0);
if(fontshow(str)) {
if(fnt->type == SP_TYPE || fnt->type == PO_TYPE) {
fontmoveto(2.0,2.0);
fntpointmode(psize);
fontshow(str);
fntpointmode(0);
cpack(0x00000000);
}
#ifdef SHOWBBOX
fontmoveto(2.0,2.0);
bboxshow(str);
#endif
}
cpack(0x00000000);
cmov2(0.0,0.0);
sprintf(doc,"Char code %d",c);
charstr(doc);
swapbuffers();
}
drawobjfnt(of)
objfnt *of;
{
int i, c;
int x, y, nc, nx, ny, cmin;
char str[2];
float fscale;
cmin = of->charmin;
nc = of->nchars;
if(nc<=96) {
nc = 96;
nx = 12;
} else {
nx = 12;
while((nx*((2*nx)/3))<nc)
nx+=3;
}
ny = (2*nx)/3;
fscale = 12.0/nx;
fontsetsize(fscale);
cpack(0x00000000);
for(i=0; i<nc; i++) {
c = i+cmin;
x = i%nx;
y = ny-1-(i/nx);
fontmoveto(fscale*x,fscale*y);
str[0] = c;
str[1] = 0;
if(fontshow(str)) {
#ifdef SHOWBBOX
cpack(0x000000ff);
fontmoveto((float)x,(float)y);
bboxshow(str);
cpack(0x00000000);
#endif
} else {
cpack(0x000000ff);
rectf(x+0.40,y+0.40,x+0.60,y+0.60);
cpack(0x00000000);
}
}
}